package com.asm.handler;

import com.asm.message.GroupMembersRequestMessage;
import com.asm.message.GroupMembersResponseMessage;
import com.asm.server.session.GroupSessionFactory;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.util.Set;


/**
 * @ClassName GroupMembersRequestMessageHandler
 * @Author ChuJinLong
 * @Date 2024/7/20 15:58
 * @Description 查看群成员信息：根据群名获取所有群成员信息。【gmembers [group name]】
 */
@ChannelHandler.Sharable
public class GroupMemberRequestMessageHandler extends SimpleChannelInboundHandler<GroupMembersRequestMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, GroupMembersRequestMessage msg) throws Exception {
        Set<String> members = GroupSessionFactory.getGroupSession().getMembers(msg.getGroupName());
          ctx.writeAndFlush(new GroupMembersResponseMessage(members));

    }
}
